package cn.tedu.csmall.product.common;

import java.util.Arrays;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

//获取两个集合中的交集
public class Demo1 {
    public static void main(String[] args) {
        Set<Integer> set1=new TreeSet<>();
        Random r=new Random();
        while (set1.size()<5){
            set1.add(r.nextInt( 20));
        }
        Set<Integer> set2=new TreeSet<>();
        while (set2.size()<10){
            set2.add(r.nextInt( 20) );
        }
        System.out.println(set2);
        System.out.println(set1);
        Set<Integer> min=set1.size()<set2.size()?set1 : set2;
        Set<Integer> max=min==set1?set2 : set1;
        Set<Integer> jj=new TreeSet<>();
        for(Integer e:min){
            if(max.contains(e)){
                jj.add(e);
            }
        }
        System.out.println(jj);

    }
}
